
import config from '@/config/config.js';
import axios from "axios";

const deviceTypeRequest = {
    /**
     * 获取父列表
     * @param searchDeviceType
     * @param callback
     */
    loadDeviceTypeList(searchDeviceType,callback){
        let url = config.deviceBaseUrl + "/deviceType/list/?deviceTypeParentId=" + searchDeviceType.deviceTypeParenId;
        if (searchDeviceType.deviceTypeName){
            url += "&deviceTypeName=" + searchDeviceType.deviceTypeName;
        }
        if (searchDeviceType.deviceTypeStatus){
            url += "&deviceTypeStatus=" + searchDeviceType.deviceTypeStatus;
        }
        console.log(url)
        axios.get(url,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callback(res.data)
        })
    },
    /**
     * 子列表获取
     * @param searchDeviceType
     * @param callback
     */
    loadDeviceTypeChildrenList(searchDeviceType,callback){
        let url = config.deviceBaseUrl + "/deviceType/childrenList/?deviceTypeParentId=" + searchDeviceType.deviceTypeParenId + "&deviceTypeParent=" +searchDeviceType.deviceTypeParent;
        if (searchDeviceType.deviceTypeName){
            url += "&deviceTypeName=" + searchDeviceType.deviceTypeName;
        }
        if (searchDeviceType.deviceTypeStatus){
            url += "&deviceTypeStatus=" + searchDeviceType.deviceTypeStatus;
        }
        console.log(url)
        axios.get(url,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callback(res.data)
        })
    },
    loadAllOptions(callback){
        let url = config.deviceBaseUrl + "/deviceType/allOptions"
        axios.get(url,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callback(res.data)
        })
    },
    insertNewDeviceType(insertDeviceType,callback){
        let url = config.deviceBaseUrl +"/deviceType/add"
        axios.post(url,insertDeviceType,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callback(res.data)
        })
    },
    loadUpdateInfo(deviceTypeId,callback){
        let url = config.deviceBaseUrl + "/deviceType/updateSearch?deviceTypeId=" + deviceTypeId;
        axios.get(url,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callback(res.data)
        })
    },
    deleteDeviceType(deviceTypeId,callback){
        let url = config.deviceBaseUrl + "/deviceType/delete?deviceTypeId=" + deviceTypeId;
        axios.delete(url,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callback(res.data)
        })
    },
    updateDeviceType(deviceType,callBack){
        let url = config.deviceBaseUrl + "/deviceType/update";
        console.log(deviceType)
        axios.put(url,deviceType,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            console.log(res.data)
            callBack(res.data)
        })
    }
}
export default deviceTypeRequest;